<?php
session_start();
if ($_SESSION['count'] == "")
{   
		$_SESSION['count'] = 1; 
}

else
{
$new_session = session_id();
	$_SESSION['count'] = $_SESSION['count'] + 1;
}
echo "<form action=\"PHP_create_user.php\" method=\"post\"><table><tr><td>Please enter a username:</td><td><input type=\"text\" name=\"newUser\"/></td></tr>
<tr><td>Please enter your password:</td><td><input type=\"password\" name=\"newPassword\"/></td></tr>
<tr><td>Please confirm your password:</td><td><input type=\"password\" name=\"confirmPassword\"/></td></tr>
</table>";
 echo "<input =\"text\" value=\"First comments...\" name=\"firstComment\" MAXLENGTH=160 size=160/><br/><input type=\"submit\" name=\"submitNew\" value=\"Submit\"/></form>";
if($_REQUEST['submitNew'] == "Submit")
 {
	 $user_check=0;
  $new_user = $_REQUEST['newUser'];
  $pass = $_REQUEST['newPassword'];
  $conpass = $_REQUEST['confirmPassword'];
  $comment = $_REQUEST['firstComment'];
  if ($pass != $conpass or $new_user =="" or $pass == "")
	 {
	  echo "<span>YOUR PASSWORDS ARE BLANK OR DON'T MATCH. PLEASE RE-ENTER PASSWORDS. MAKE SURE THE USERNAME IS NOT BLANK!</span><br/>";
	  if ( $comment=""){echo "<span>Please don't leave an empty comment!</span>";}
	 }
	 else
	 {
	  $conn = mysql_connect('mysql2.freehostia.com','vlamat3_CS4350','lab');
      $db = mysql_select_db('vlamat3_CS4350', $conn);
	   $sql = "SELECT * FROM `Comments_text` WHERE user != '0' ";
          $rs = mysql_query($sql, $conn);
	  $current_date= date("Y-m-d H:i:s");
                while($row = mysql_fetch_array($rs)) 
    
                 {
	       	      if ($new_user == $row['user'])
					  {
					  exit("Such username already exists");
					  $user_check=1;
			      	  }
                 
				 }
	  if($user_check != 1)
		 {
	  $sql = "INSERT INTO `Comments_text` VALUES('$new_session', '$new_user', '$pass','$current_date','$comment')";
	      mysql_query($sql, $conn);
		  echo "<input type=\"button\" value=\"Close\" onclick=\"window.close();\">";

		 }
	 }
	
 }
 ?>
